from django.db import models

# Create your models here.

# 建立数据库类
class User(models.Model):
    id = models.AutoField(primary_key=True)
    # 用户名
    username = models.CharField(max_length=200)
    # 密码
    password = models.CharField(max_length=200)
    # 头像
    img = models.ImageField(upload_to='static/img/')
    # 类别 0代表学生 1代表老师
    type =  models.IntegerField()
    #声明表明
    class Meta:
        db_table = 'user'

    def __str__(self):
        return self.username


# 课程分类
class Category(models.Model):
    # 主键 通过参数声明主键
    id = models.AutoField(primary_key=True)
    # 分类名称
    name = models.CharField(max_length=200)

    class Meta:
        db_table = 'category'

#课程表
class Course(models.Model):
    # 主键 通过参数声明主键
    id = models.AutoField(primary_key=True)
    # 课程标题
    title = models.CharField(max_length=200)
    # 课程内容
    desc = models.CharField(max_length=500)
    # 上传图片
    img = models.ImageField(upload_to='static/img/')
    # 价格
    price = models.IntegerField()
    # 类别id
    cid = models.IntegerField()
    # 用户id
    uid = models.IntegerField()
    # 关注数
    flow = models.IntegerField(default=0,null=True)

    class Meta:
        db_table = 'course'



